#include <Variable.au3>
#include <Func.au3>








;Action= 1 (Install) or 2 (Uninstall) or 3 (Upgrade)

; #CURRENT# ----------------------------------------------
; Main
; downloadDS
; action()
;--------------------------------------------------------- 


Main()

; #Function# ---------------------------------------------
; Name...........: downloadDS()
; Description ...: 
; Parameters ....: 
; Return values .: NA
;----------------------------------------------------------

Func downloadDS()
	
	if $action<>2 And FileExists($G_DSexePath & $G_DSexeName)<>1 Then
		
		RunWait("download_DS.bat")
	
	EndIf

EndFunc



; #Function# ---------------------------------------------
; Name...........: Main
; Description ...: 
; Parameters ....: 
; Return values .: NA
;----------------------------------------------------------

Func Main()
	
	
	
	;MsgBox(0,"Test","Main Start...")
	
	_log("Main() IN")
	$record = IniRead($G_tmpFile,$tmp_RecordSection,$tmp_RecordKey,$tmp_FileNotFound)	
	
	Switch $record
		Case $tmp_FileNotFound			;---Before Reboot
			_log("$tmp_File Not Found")	
			
			;downloadDS()
			
			IniWrite($G_tmpFile,$tmp_RecordSection,$tmp_RecordKey,"1")
			
			generate_configure_result($S_file)			
			action()
		
		Case 1							;---After Reboot
		
			Sleep("5000")			
			
			generate_configure_result($D_file) 			
			
			iniFileCompare($S_file,$D_file,$SDcompare_file)	
			_progressSet(" ", "Compare source and destination files")				
			
			transfer_Para_in_File($E_file,$E_fileNew,$globalvariable_file_name)						
			_progressSet(" ", "Compare file with expected files")
			
			iniFileCompare_byE($SDcompare_file,$E_fileNew,$R_file,$Report_file)
		
			
			FileDelete($G_tmpFile)			
			$action = get_action()
			
			Switch $action				
				Case 1
					$actionStr = "Install"						
				Case 2
					$actionStr = "Uninstall"
					
				Case 3
					$actionStr = "Upgrade"
					
			EndSwitch

			;open report
			;ShellExecute(@ProgramFilesDir&"\FalconStor\DiskSafe\DiskSafe.msc")			
			Run("notepad.exe " & $Report_file)
			MsgBox(0,"",$actionStr & " Complete!")
			;Run(@ComSpec & " /c " & 'c:\DSupgrade_Report.xml', "C:\", @SW_HIDE) ; don't forget " " before "/
	
	EndSwitch
		
	_log("Main() OUT")	
	
EndFunc
	
	
; #Function# ---------------------------------------------
; Name...........: action()
; Description ...: Run install, uninstall or upgrade and reboot
; Parameters ....: 
; Return values .: NA
;----------------------------------------------------------

Func action()
	
	Switch $G_Action
		Case "1"									;Install
		_progressSet("Install", "Running...")
		Func_Install($G_DSexePath,$G_DSexeName)
		
		Case "2"									;Uninstall
		_progressSet("Uninstall", "Running...")
		Func_Uninstall()
		
		Case "3"									;Upgrade
		_progressSet("Upgrade", "Running...")		
		Func_Upgrade($G_DSexePath,$G_DSexeName)
	EndSwitch
	
EndFunc